﻿using DataEntity.Entities;
using IService;
using Microsoft.EntityFrameworkCore;
using Model.SectionDTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Service
{

    public class SectionService: ISectionService
    {
        #region 构造函数依赖注入

        private readonly DbContext _dbContext;
        public SectionService(DbContext dbContext)
        {
            _dbContext = dbContext;
        }
        #endregion
        /// <summary>
        /// 添加板块
        /// </summary>
        /// <param name="regInput"></param>
        /// <returns></returns>
        public bool AddSection(SectionInput regInput)
        {
            var Isection = _dbContext.Set<TmessCategory>().Where(u => u.Category == regInput.Category).FirstOrDefault();
            if (Isection != null)
            {
                return false;
            }
            else
            {
                _dbContext.Add(new TmessCategory
                {
                   Category  = regInput.Category,
                   CategoryEnable=regInput.CategoryEnable,
                });
                int results = _dbContext.SaveChanges();
                if (results > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
    }
}
